# -*- coding:utf-8 -*-

'''
PROJECT_NAME : python_高级
file    : check_type
author  : 1032162439@qq.com
date    : 2022-11-08 11:29
IDE     : PyCharm
'''


class FloatCheck:
    def __init__(self, value):
        self.value = value

    def __get__(self, instance, owner):
        return instance.__dict__[self.value]

    def __set__(self, instance, value):
        if not isinstance(value, float):
            raise TypeError('value must be float!')
        instance.__dict__[self.value] = value


class StrCheck:
    def __init__(self, value):
        self.value = value

    def __get__(self, instance, owner):
        return instance.__dict__[self.value]

    def __set__(self, instance, value):
        if not isinstance(value, str):
            raise TypeError('value must be string!')
        instance.__dict__[self.value] = value


class Hero:
    name = StrCheck('name')
    blood = FloatCheck('blood')

    def __init__(self, name: str, blood: float):
        self.name = name
        self.blood = blood


def test_blood():
    h = Hero('鲁班', 100.0)
    print(h.name, h.blood)


if __name__ == '__main__':
    test_blood()
